<!--浙里办危改选则鉴定公司-->
<template>
  <div id="ApplyappraisalCompany">
    <van-tabs v-model="active" @click="handleclickto" :active="active" swipeable>
      <van-tab title="选择鉴定公司">
        <div style="padding: 4px">
          <van-search v-model="QYMC" style="border-radius: 10px; height: 44px" background="#f7f8fa"
            placeholder="请输入企业名称检索" @search="onSearch" />
          <span style="
          width: 120px;
          height: 40px;
          display: inline-block;
          line-height: 40px;
          text-align: center;
        ">共计：{{ JDGSData.length }}家</span>
        </div>
        <div style="height: 72vh;overflow:auto;">
          <van-field readonly clickable name="picker" clear-trigger :value="JDJG" label="注册地" placeholder="请选择注册地"
            @click="showJDGS = true" />
          <van-popup v-model="showJDGS" position="bottom" get-container="#popup">
            <van-picker show-toolbar :columns="cityData" value-key="cityname" @confirm="onConfirmJDGS"
              @cancel="showJDGS = false" />
          </van-popup>
          <van-list finished-text="没有更多了">
            <van-cell v-for="(item, index) in JDGSData" :key="index">
              <ul>
                <li>
                  <p style="font-weight: bold; margin-bottom: 8px; height: 3vh">
                    <img @click="changeData(item)" v-if="!item.checked"
                      src="https://nfzjszlb.jst.zj.gov.cn/serverfile/zheliban/icon/ZLJ/WXZ.png">
                    <img @click="changeData(item)" v-if="item.checked"
                      src="https://nfzjszlb.jst.zj.gov.cn/serverfile/zheliban/icon/ZLJ/XZ.png">

                    <span style>{{ item.qymc }}</span>
                  </p>
                  <p style="font-size: 14px; color: #848484">
                    <span style="float: left">注册地：{{ item.cityName }}</span>
                    <span style="float: right">企业信用码：{{ item.zzjgdm }}</span>
                  </p>
                  <p style="clear: both; display: flex; align-items: center;font-size: 14px; color: #848484">
                    <span style="float: left">法人：{{ item.frxm }}</span>
                  </p>
                  <p style="clear: both; display: flex; align-items: center;font-size: 14px; color: #848484">
                    <span style="float: left">通讯地址：{{ item.dwdz }}</span>
                  </p>
                </li>
              </ul>
            </van-cell>
          </van-list>
        </div>
        <div style="position:fixed;bottom: 10px;width: 100%;">
          <span class="bottomBtn" @click="SaveData(true)">下一步</span>
        </div>
      </van-tab>
    </van-tabs>
  </div>
</template>

<script>
import { FileServerProxy, saveAuthInfo, saveAuthInfoV2, appraisal, appraisalV2, objectNoTransfer, selectTechnicalList, GetAdministrative } from "@/utils/api";
import patrolInformation from "../../activity/ZDPC/formPanel/patrolInformation";
import houseSafetyChecklist from "../../activity/ZDPC/formPanel/houseSafetyChecklist";
import { Dialog } from "vant";
export default {
  name: "ApplyappraisalCompany",
  data() {
    return {
      IsNewDanger: false,
      loading: false,
      finished: false,
      QYMC: '',
      objectNo: "",
      active: 2,
      JDJG: '',
      uscc: '',
      showJDGS: false,
      JDGSData: [

      ],
      rowData: {},
      cityData: '',
      citycode: '',
      JDJGS: ''
    }
  },
  methods: {
    handleclickto() {

    },
    onSearch() {
      debugger
      this.getJDGSData()
    },
    changeData(data) {
      this.JDGSData.forEach((item, index) => {
        if (data.id == item.id) {
          item.checked = true
          this.JDJGS = item.qymc
          this.uscc = item.zzjgdm
          this.$forceUpdate()
        } else {
          item.checked = false
          this.$forceUpdate()
        }
        // this.$forceUpdate()
      })
    },
    getJDGSData: async function () {
      let param = {
        "belongCountryList": [],
        "belongCountyList": this.citycode ? [this.citycode] : [],
        "name": this.QYMC,
        "pageNo": 1,
        "fwlx": "鉴定机构",
        //"qymc": this.QYMC,
        "pageSize": 100000,
        "cityCode": '',
        "token": null
      };
      const res = await selectTechnicalList(param);
      if (res.data && res.data.data && res.data.data.pageList.length > 0) {
        this.JDGSData = res.data.data.pageList;
        this.JDGSData.forEach((item, index) => {
          item.checked = false
          this.$forceUpdate()
        })
      } else {
        this.JDGSData = [];
      }

    },
    getCityData: async function () {
      var res1 = await GetAdministrative("330000000000")
      console.log(res1)
      this.cityData = res1.data.data
      this.cityData.push({
        cityname: '',
        citycode: ''
      })

    },
    onConfirmJDGS(data) {
      this.JDJG = data.cityname
      this.citycode = data.citycode
      this.showJDGS = false
      this.getJDGSData()
    },
    SaveData: async function (item) {
      debugger
      var me = this;
      if (!me.JDJGS) {
        me.$toast.fail("请选择鉴定公司！")
        return;
      }
      Dialog.confirm({
        message: `您当前选择的鉴定公司是${this.JDJGS},是否确认提交`,
      })
        .then(async () => {
          debugger
          // on confirm
          let param = {
            objectNo: me.rowData.objectNo,
            isAuth: '否',
            recheck: 0,
            authCompanyName: me.JDJGS,
            socialCreditCode: me.uscc,
          }
          var reswebResult = "";
          if (me.IsNewDanger) {
            param.companyUscc = me.uscc;
            param.companyName = me.JDJGS;
            param.origin = "ZLB";
            reswebResult = await saveAuthInfoV2(param);
          } else {
            reswebResult = await saveAuthInfo(param);
          }
          if (reswebResult.data.data) {
            if (me.IsNewDanger) {
              this.$router.push({
                path: '/ZLJIndex',
              })
              // var params2 = {
              //   "objectNo": me.rowData.objectNo,
              //   "userName": JSON.parse(window.localStorage.getItem('userName')).userName,
              //   "userId": "",
              //   "origin": "ZLB",
              //   "processNode": me.rowData.processNode
              // }
              // const resResult = await saveAuthInfoV2(params2)
              // if (resResult.data.data) {
              //   this.$router.push({
              //     path: '/ZLJIndex',
              //   })
              // } else {
              //   this.$toast.fail(resResult.data.msg)
              // }
            } else {
              let params1 = {
                objectNo: me.rowData,
                userName: window.localStorage.getItem('DanDianName'),
                authCompanyName: me.JDJGS,
                socialCreditCode: me.uscc,
                recheck: 0,
                token: window.localStorage.getItem('token'),
                isAuth: '否',
                authLevel: 'D',
              }
              const res1 = await appraisal(params1);
              console.log(res1)
              if (res1.data.data) {
                this.$router.push({
                  path: '/ZLJIndex',
                })
              } else {
                this.$toast.fail(res1.data.msg)
              }
            }

          } else {
            this.$toast.fail(res.data.msg)
          }
        })
        .catch(() => {

        });

    },

  },
  mounted() {
    debugger
    //通过危改的objtctNo 获取安全的objectNo
    if (this.$route.query.data) {
      this.rowData = this.$route.query.data
    }
    if (this.$route.query.data && this.$route.query.type == "true") {
      //新危改进来的
      this.IsNewDanger = true;
      this.rowData = JSON.parse(this.$route.query.data);
    }
    // console.log(JSON.parse(this.$route.query.data))
    this.getJDGSData()
    this.getCityData()
  },
  components: {
    patrolInformation,
    houseSafetyChecklist
  },
};
</script>

<style scoped lang="scss">
#ApplyappraisalCompany {
  width: 100%;
  height: 100vh;
  padding: 10px;

  .bottomBtn {
    width: 95%;
    height: 40px;
    background: #007aff;
    line-height: 40px;
    text-align: center;
    color: #ffffff;
    font-weight: bold;
    display: inline-block;
  }
}
</style>

